package GoldMiner.com.ALi;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;

/**
 * @author ：ALi
 * @date ：Created in 2021/10/31 9:36
 * @description：背景图片加载类
 * @modified By：
 * @version: $
 */
public class BackGroundImgs {
    /**
     * 获取图片
     * @param backGround为加载的背景图片
     */
    private Image backGround = Toolkit.getDefaultToolkit().getImage("imgs/bg.jpg");
    private Image backGround_sky = Toolkit.getDefaultToolkit().getImage("imgs/bg1.jpg");
    private Image backGround_person = Toolkit.getDefaultToolkit().getImage("imgs/peo.png");
    private Image backGround_water = Toolkit.getDefaultToolkit().getImage("imgs/water.png");
    //总分
    protected static int count = 0;
    //药水数量：初始值为3
    protected static int WaterNamber = 3;
    //药水状态 false为未使用
    protected static boolean WaterFlag = false;
    //关卡数
    protected static int level = 1;
    //关卡目标得分
    protected static int goal = level*15;
    //开始时间
    protected static long startTime;
    //关闭时间
    protected static long endTime;
    //药水价格
    protected int price = (int)(Math.random()*10);
    //是否进入商店
    protected boolean shop = false;
    /**
     * 将图片画在窗口上
     * @param graphics 画笔
     */
    void painImgs(Graphics graphics){

        //绘制背景图片（人，天空，地下）
        graphics.drawImage(backGround,0,200,null);
        graphics.drawImage(backGround_sky,0,0,null);
        switch (GameWin.state){
            case 0:
                drawWord(graphics,70,"右键进入游戏",170,400,Color.BLACK);
                break;
            case 1:
                graphics.drawImage(backGround_person,310,50,null);
                //药水
                graphics.drawImage(backGround_water,450,40,null);
                drawWord(graphics,30,"*"+WaterNamber,510,70,Color.BLACK);

                drawWord(graphics,30,"积分:"+count,30,150,Color.BLACK);

                //绘制关卡数
                drawWord(graphics,20,"第:"+level+" 关",30,60,Color.BLACK);
                //显示积分
                drawWord(graphics,30,"目标:"+goal,30,110,Color.BLACK);
                //实时赋值
                endTime = System.currentTimeMillis();
                long tim = 20 - (endTime - startTime)/1000;
                drawWord(graphics,30,"时间:"+(tim>0?tim:0),520,150,Color.BLACK);

                break;
            case 2:
                graphics.drawImage(backGround_water,300,400,null);
                //显示积分
                drawWord(graphics,30,"价格:"+price,300,500,Color.BLACK);
                drawWord(graphics,30,"是否购买:",300,550,Color.BLACK);
                if(shop){
                    count = count - price;
                    WaterNamber++;
                    shop = false;
                    GameWin.state = 1;
                    startTime = System.currentTimeMillis();
                }
                break;
            case 3:
                drawWord(graphics,80,"失败",250,350,Color.red);
                drawWord(graphics,80,"积分:"+count,200,450,Color.red);
                break;
            case 4:
                drawWord(graphics,80,"成功",250,350,Color.green);
                drawWord(graphics,80,"积分:"+count,200,450,Color.green);
                break;
            default:
        }



    }
    /**
     * create by: ALi
     * description: 打印字符串
     * create time: 2021/10/31 13:57
     * @Param: null
     * @return
     */
    public static void drawWord(Graphics graphics,int size,String str,int x,int y,Color color){
        //显示积分
        graphics.setColor(color);
        graphics.setFont(new Font("仿宋",Font.BOLD,size));
        graphics.drawString(str,x,y);
    }

    /**
     * create by: ALi
     * description: 判断是否完成关卡
     * create time: 2021/10/31 15:28
     *
      * @Param: null
     * @return
     */
    public boolean gameTime(){
        long tim = (endTime - startTime)/1000;
        if (tim >20){
            return true;
        }else{
            return false;
        }
    }

    public void reGame(){
        level = 1;
        goal  = level * 15;
        count = 0;
        WaterNamber = 3;
        WaterFlag = false;

    }
}
